<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>websocket 测试</title>
    </head>
    <body>
        <h1>websocket 测试ss</h1>
        <script type="text/javascript">
            var wsServer = 'ws://sw.xxmall.com:9119';
            var websocket = new WebSocket(wsServer);

            websocket.onopen = function(evt){
                console.log('connected to websocket server success.');
                websocket.send('你好啊，来自浏览器的问候');
            };

            websocket.onclose = function(evt){
                console.log('断开连接');
            };

            // 实例化onmessage
            websocket.onmessage = function(evt){
                console.log('浏览器获取的数据'+ evt.data);
            }

            websocket.onerror = function(evt,e){
                console.log('错误发生了' + evt.data);
            }

        </script>
    </body>
</html>